<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/common.css" rel="stylesheet" />
		<style>
			.mui-table-view{
				margin-top: 16px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav xq-window-header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">设置</h1>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					缓存浏览记录
					<div class="mui-switch mui-switch-mini" id='history-enable-switch'>
						<div class="mui-switch-handle"></div>
					</div>
				</li>
			</ul>
			<ul class="mui-table-view">
			    <li class="mui-table-view-cell" id='to-shiwen-det-page-setting'><span class="mui-navigate-right">诗文详情页设置</span></li>
				<li class="mui-table-view-cell" id='to-writer-det-page-setting'><span class="mui-navigate-right">作者详情页设置</span></li>
			</ul>
			<ul class="mui-table-view">
				<li class="mui-table-view-cell mui-collapse mui-active">
					<a class="mui-navigate-right">字体管理</a>
					<div class="mui-collapse-content">
						<form class="mui-input-group" id="font-sel-form">
							<div class="mui-input-row mui-radio">
								<label style="font-family: 'Helvetica Neue',Helvetica,sans-serif;">默认字体</label>
								<input name="font-sel" type="radio" value="_system">
							</div>
							<div class="mui-input-row mui-radio">
								<label style="font-family: hanyikaitijinan;">汉仪楷体</label>
								<input name="font-sel" type="radio" value="hanyikaitijinan">
							</div>
						</form>
					</div>
				</li>
			</ul>
			<!-- <ul class="mui-table-view">
				<li class="mui-table-view-cell mui-collapse">
					<a class="mui-navigate-right">环境选择</a>
					<div class="mui-collapse-content">
						<form class="mui-input-group" id="env-sel-form">
							<div class="mui-input-row mui-radio">
								<label>本地</label>
								<input name="env-sel" type="radio" value="local">
							</div>
							<div class="mui-input-row mui-radio">
								<label>测试</label>
								<input name="env-sel" type="radio" value="test">
							</div>
						</form>
					</div>
				</li>
			</ul> -->
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/jquery-3.3.1.js"></script>
		<script src="../js/commonUtils.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.ready(function(){
				if(mui.os.plus){
					return;
				}
				initSettingPage();
			});
			
			mui.plusReady(function () {
			    initSettingPage();
			})
			
			
			function initSettingPage(){
				SettingInfoManager.setPageFontFromSetting();
				//
				mui('#env-sel-form').on('change', 'input', function() {
					if (this.checked) {
						var envVal=this.value;
						console.info(envVal);
						if(envVal=='local'){
							SettingInfoManager.setEnv('local');
						}else if(envVal=='test'){
							SettingInfoManager.setEnv('test');
						}
						mui.toast('设置成功',{ duration:'long', type:'div' });
					}
				});
				//
				mui('#font-sel-form').on('change', 'input', function() {
					if (this.checked) {
						var fontVal=this.value;
						console.info("fontVal="+fontVal);
						SettingInfoManager.setFont(fontVal);
						mui.toast('设置成功',{ duration:'long', type:'div' });
					}
				});
				//
				$('#history-enable-switch').on('toggle',function(e){
					if(event.detail.isActive){
					    console.log("你启动了开关");
						SettingInfoManager.setEnabledHistory(true);
					 }else{
					    console.log("你关闭了开关");  
						SettingInfoManager.setEnabledHistory(false);
					 }
				});
				//
				$('#to-shiwen-det-page-setting').on('tap', function(e) {
					mui.openWindow({
						url:'settingOfGushiwenDetai.html',
						id:'settingOfGushiwenDetai.html'
					});
				});
				//
				$('#to-writer-det-page-setting').on('tap', function(e) {
					mui.openWindow({
						url:'settingOfWriterDetai.html',
						id:'settingOfWriterDetai.html'
					});
				});
				//
				initCurrentEnv();
				initCurrentFont();
				initHistoryEnableSwitch();
			}
			
			function initCurrentEnv(){
				if(getShiciServiceHost() == appConfig.shiciLocalServiceHost){
					$('#env-sel-form').find('[value="local"]').attr('checked','true');
				}else if(getShiciServiceHost() == appConfig.shiciTestServiceHost){
					$('#env-sel-form').find('[value="test"]').attr('checked','true');
				}
			}
			
			function initCurrentFont(){
				var fontVal = SettingInfoManager.getFont();
				if(fontVal){
					$('#font-sel-form').find('[value="'+fontVal+'"]').attr('checked','true');
				}
				
			}
			
			function initHistoryEnableSwitch(){
				if(SettingInfoManager.getEnabledHistory()){
					$('#history-enable-switch').addClass('mui-active');
				}else{
					$('#history-enable-switch').removeClass('mui-active');
				}
			}
		</script>
	</body>

</html>
